package com.it.a03udpdemo2;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class SendMessageDemo {
    public static void main(String[] args) throws IOException {
        //创建对象DatagramSocket
        DatagramSocket ds = new DatagramSocket();
        //打包数据
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入你要说的话:");
            String str = sc.nextLine();
            if("886".equals(str)) {
                break;
            }
            byte[] data = str.getBytes();
            InetAddress address = InetAddress.getByName("127.0.0.1");
            int port = 10086;
            DatagramPacket dp = new DatagramPacket(data, data.length, address, port);
            ds.send(dp);
        }
        //释放资源
        ds.close();
    }
}
